package com.fuershiye.woman.monitor.utils;

import com.fuershiye.woman.monitor.beans.Page;
import com.fuershiye.woman.monitor.model.Indicator;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.poi.ss.formula.functions.T;

import java.util.*;

public class PageUtil {


	public static List<Map<String, Object>> getPage(Page page, List<Map<String, Object>> list) {

		List<Map<String, Object>> result = Lists.newArrayList();

		if(page.getPage()<1||page.getPageSize()<1||list.size()<1){
			return result;
		}

		int i=0;
		for (Map<String, Object> map:list){
			if(i>=page.getStart()){
				result.add(map);
			}
			if(i>=page.getPageEnd()){
				return result;
			}
			i++;
		}
		return result;
	}

	public static List<Indicator> getPageIndicator(Page page, List<Indicator> list) {

		List<Indicator> result = Lists.newArrayList();

		if(page.getPage()<1||page.getPageSize()<1||list.size()<1){
			return result;
		}

		int i=0;
		for (Indicator indicator : list){
			if(i>=page.getStart()){
				result.add(indicator);
			}
			if(i>=page.getPageEnd()){
				return result;
			}
			i++;
		}
		return result;
	}


	public static void main(String[] args) throws Exception {

		List<Map<String, Object>> list = Lists.newArrayList();
		Map<String, Object> map1= Maps.newHashMap();
		map1.put("name",1);
		list.add(map1);
		Map<String, Object> map2= Maps.newHashMap();
		map2.put("name",2);
		list.add(map2);
		Map<String, Object> map3= Maps.newHashMap();
		map3.put("name",3);
		list.add(map3);
		Map<String, Object> map4= Maps.newHashMap();
		map4.put("name",4);
		list.add(map4);
		Map<String, Object> map5= Maps.newHashMap();
		map5.put("name",5);
		list.add(map5);

		List<Map<String, Object>> result = getPage(new Page(2,1), list);
		for (Map<String, Object> map:result){
			System.out.println(map.get("name"));
		}
	}

}